home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 451-475 / disk_457 / cmanual / acm4.lzh / FileWindow / FileWindow.c < prev    next >
Text File  |  1991-01-12  |  70KB  |  2,504 lines

  1. /* Name: FileWindow.c
  2.  
  3.  
  4.   FFFFF III L     EEEEE     W     W III N   N DDD    OOO  W     W
  5.   F      I  L     E         W     W  I  NN  N D  D  O   O W     W
  6.   FFFF   I  L     EEE       W  W  W  I  N N N D   D O   O W  W  W
  7.   F      I  L     E          W W W   I  N  NN D  D  O   O  W W W
  8.   F     III LLLLL EEEEE       W W   III N   N DDD    OOO    W W
  9.  
  10.  
  11.   
  12.   FILE WINDOW   VERSION 1.20   90-01-30
  13.  
  14.   Yet another program dedicated to Sioe-Lin Kwik.
  15.   
  16.  
  17.   FILE WINDOW was created by Anders Bjerin, and is distributed as
  18.   public domain with NO RIGHTS RESERVED. That means that you can do
  19.   what ever you want with the program.
  20.   
  21.   You may use FILE WINDOW in your own programs, commercial or not, and 
  22.   do not even need to mention that you have used it. You may alter the
  23.   source code to fit your needs, and you may spread it to anyone.
  24.   
  25.   
  26.   
  27.   
  28.   The reason why I created FILE WINDOW was that I never more wanted to
  29.   see that old stupid "Please type in filename:" prompt. It is a disgrace
  30.   for any program to use it, and VERY annoying for the user.
  31.   
  32.   REMEMBER, one of the first things the user will see of your program is
  33.   the file requester. If you want your program to make a good impression,
  34.   and look solid, I would recommend you to use a good file requester.
  35.   
  36.   FILE WINDOW is written to be as easy as possible to use, and is fully
  37.   amigaized. It is similar to other good file requesters, but has several
  38.   advantages:
  39.   
  40.    1. FILE WINDOW dynamically allocates memory for each file. That means
  41.       that there is no memory wasted as it would have been if you had
  42.       statically allocated the filenames in arrays. It also means that the 
  43.       memory is the only limitation on how many files the program can
  44.       display.
  45.  
  46.    2. While FILE WINDOW is reading the directories, it is still obeying
  47.       your commands. You may change directory, type in the file name
  48.       yourself etc etc while the program still is working. All of us know
  49.       how irritating it is to see the little Zzz pointer in a program
  50.       while the disk is examined. This is especially annoying when you know
  51.       the filename, and only want to type it in.
  52.  
  53.    3. FILE WINDOW was written for the Amiga. It uses boolean, string and
  54.       proportional gadgets, and is using them as recommended. For example,
  55.       the proportional gadget's knob changes size corresponding to how
  56.       many files/directories there are. (It is strange that there are
  57.       several file requesters using a static small knob instead. That
  58.       makes it much harder for the user to see how many files there are in
  59.       the directory.)
  60.  
  61.    4. There are three boolean gadgets which allows the user to quickly 
  62.       select df0:, df1: and dh0:.
  63.  
  64.       5. FILE WINDOW has a boolean gadget "<" which steps back one directory
  65.       each time it is pressed. (Same as "/ Parent dir")
  66.  
  67.    6. You can specify a file-extension, and only the files with that
  68.       extension will be displayed. (Directories are always showed.)
  69.       The user can also change the extension since it is a string gadget.
  70.       (If there are any characters in the string gadget, the text "Ext:"
  71.       will be highlighted to tell the user that EXTENSION MODE is on.)
  72.  
  73.    7. The files/directories are automatically sorted alphabetically while
  74.       they are taken from the disk. Directories first, highlighted with the
  75.       ending (Dir), and then the files.
  76.  
  77.    8. FILE WINDOW deallocates all memory allocated, and is fool proof. If
  78.       something goes wrong (not enough memory, wrong directory name etc),
  79.       the program will open a requester and tell the user what the 
  80.       problem is.
  81.  
  82.    9. The source code is distributed with the program so you can alter it
  83.       to fit your needs.
  84.  
  85.   10. FILE WINDOW is not as a normal file requester, since it uses a
  86.       (surprise, surprise) window instead of a requester to display the
  87.       files on. That means that the calling program does not need to
  88.       have a window itself, to be able to use FILE WINDOW. (A normal
  89.       requester always needs a pointer to a window.)
  90.  
  91.   11. There are no Image structures in the code, so FILE WINDOW does not
  92.       need to be in the CHIP memory.
  93.  
  94.   12. The width of the window is 320, which means that any program can use
  95.       it, both in High as well as Low resolution.
  96.  
  97.   13. When FILE WINDOW has examined all files in the directory, the
  98.       program is put to sleep. That will speed up other programs, and 
  99.       will not use unnecessary processing time.
  100.  
  101.   14. Fast updating of the display.
  102.  
  103.   15. FILE WINDOW was created by Anders Bjerin.
  104.  
  105.  
  106.  
  107.   FILE WINDOW is very easy to install in your program, and I have even
  108.   done an example on how to use it. The source code is full of comments
  109.   to make it easier for you to change something in the program, but
  110.   if you would have any problems, feel free to contact me. I can even
  111.   make small changes for you personally if you have problems with
  112.   understanding the code, and it will not cost you anything.
  113.  
  114.   If you have any questions, ideas, programs (PD or your own) etc etc,
  115.   or just want to say hello, PLEASE WRITE TO ME:
  116.  
  117.   Anders Bjerin
  118.   39 Sydney Road
  119.   Richmond
  120.   Surrey  TW9 1UB
  121.   ENGLAND
  122.  
  123.   After Feb 1990:
  124.   Tulevagen 22
  125.   181 41  LIDINGO
  126.   SWEDEN
  127.  
  128.  
  129.  
  130.   FILE WINDOW will look something like this when you run it:
  131.  
  132.   -----------------------------------
  133.   |#| TITLE                   |==|==|
  134.   |---------------------------------|
  135.   | df0: | df1: | dh0: | Ext:XXXXXX |
  136.   |---------------------------------|
  137.   | Drawer: XXXXXXXXXXXXXXXXXXXX |<<|
  138.   |---------------------------------|
  139.   |                              |XX|
  140.   |        FILE DISPLAY          |XX|
  141.   |                              |XX|
  142.   |                              |XX|
  143.   |                              |XX|
  144.   |                              |OO|
  145.   |                              |OO|
  146.   |                              |OO|
  147.   |---------------------------------|
  148.   | File: XXXXXXXXXXXXXXXXXXXXXXXXX |
  149.   |---------------------------------|
  150.   | LOAD | SAVE | DELETE | CANCEL | |
  151.   -----------------------------------
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.   FFFFF III L     EEEEE     W     W III N   N DDD    OOO  W     W
  161.   F      I  L     E         W     W  I  NN  N D  D  O   O W     W
  162.   FFFF   I  L     EEE       W  W  W  I  N N N D   D O   O W  W  W
  163.   F      I  L     E          W W W   I  N  NN D  D  O   O  W W W
  164.   F     III LLLLL EEEEE       W W   III N   N DDD    OOO    W W
  165.  
  166.   III N   N FFFFF  OOO  RRRR  M   M  AAA  TTTTTTT III  OOO  N   N
  167.    I  NN  N F     O   O R   R MM MM A   A    T     I  O   O NN  N
  168.    I  N N N FFF   O   O RRRR  M M M AAAAA    T     I  O   O N N N
  169.    I  N  NN F     O   O R  R  M   M A   A    T     I  O   O N  NN
  170.   III N   N F      OOO  R   R M   M A   A    T    III  OOO  N   N
  171.  
  172.  
  173.  
  174.  
  175.   HOW TO USE IT:
  176.  
  177.  
  178.   operation=FileWindow( title, extension, x, y, screen, file );
  179.        
  180.   
  181.   operation: a variable which will contain the "flags" FILE WINDOW
  182.              returned.
  183.   title:     string containing the name of the FILE WINDOW.
  184.   extension: string to be used as a file extension.
  185.   x:         x position of the FILE WINDOW.
  186.   y:         y position of the FILE WINDOW.
  187.   screen:    pointer to a screen if there exist one.
  188.   file:      a string which will contain the file name together with
  189.              the entire path. (For example: "df0:letters/payments.doc"
  190.  
  191.  
  192.  
  193.   Title is a string which will appear on the drag gadget. Write NULL if
  194.   you do not want any string there.
  195.  
  196.   Extension is a 7 character long string. 6 letters and the NULL ('\0')
  197.   sign. If you give FILE WINDOW a string, the program will only display
  198.   the files which endings match with your string. (Directories will always
  199.   be displayed.) If you do not want to use a file extension you simply
  200.   write NULL.
  201.   
  202.   The width of the window is 320 pixels which means that if you are using
  203.   a low resolution display (320 pixels) x should be initialized to be 0.
  204.   If you are using a high resolution display (640 pixels) x can be
  205.   between 0 and 320.
  206.  
  207.   On a NTSC screen (200 lines) y can be between 0 and 37. On a PAL screen
  208.   (256 lines) between 0 and 93.
  209.   
  210.   If your program is using a CUSTOM SCREEN you should give FILE WINDOW a
  211.   pointer to your screen. Otherwise, if you are using a WBENCH SCREEN you
  212.   simply write NULL.
  213.   
  214.   Name is a string which can already contain a file name with path if
  215.   you want. If the string is empty, FILE WINDOW will start to display the
  216.   current directory. When the user has selected the file to LOAD or SAVE it
  217.   is here you should look for the file name with path.
  218.   
  219.  
  220.  
  221.   For examples:
  222.     
  223.     1. operation=FileWindow( NULL, NULL, 0, 0, NULL, file);
  224.  
  225.        operation has been declared as: USHORT operation;
  226.        file has been declared as     : UBYTE file[TOTAL_LENGTH];
  227.     
  228.  
  229.     2. operation=FileWindow(title, ext, x, y, my_screen, file);
  230.        
  231.        operation has been declared as: USHORT operation;
  232.        title           -"-           : UBYTE title[ANY_LENGTH];
  233.        ext             -"-           : UBYTE ext[7];
  234.        x, y            -"-           : SHORT x, y;
  235.        my_screen       -"-           : struct Screen *my_screen;
  236.        file            -"-           : UBYTE file[TOTAL_LENGTH];
  237.  
  238.  
  239.   Remember to "include" the file "FileWindow.h"!
  240.   ex: #include "FileWindow.h"
  241.  
  242.  
  243.   Program:                 FileWindow
  244.   Version:                 1.20
  245.   Programmer:              Anders Bjerin
  246.   Language:                C (100%)
  247.   Compiler:                Lattice C Compiler, V5.02
  248.   Linker:                  Blink, V5.02
  249.   AmigaDOS:                V1.2 and V1.3
  250.   Ref. nr:                 3A-146-1
  251.  
  252.   Amiga is a registered trademark of Commodore-Amiga, Inc.
  253.   AmigaDOS is a registered trademark of Commodore-Amiga, Inc.
  254.   Lattice is a registered trademark of Lattice, Inc.
  255.  
  256.  
  257.   For more information see the file "Example.c".
  258.  
  259.   ENJOY YOUR AMIGA, AND MAKE EVERYONE ELSE ENJOY IT TOO!
  260.  
  261.   Anders Bjerin
  262.   
  263. */
  264.  
  265. #include <exec/types.h>
  266. #include <exec/nodes.h>
  267. #include <exec/lists.h>
  268. #include <exec/libraries.h>
  269. #include <exec/ports.h>
  270. #include <exec/interrupts.h>
  271. #include <exec/io.h>
  272. #include <exec/memory.h>
  273. #include <libraries/dos.h>
  274. #include <libraries/dosextens.h>
  275. #include <intuition/intuition.h>
  276. #include <string.h>
  277.  
  278. #include "FileWindow.h"
  279.  
  280.  
  281.  
  282. /* Declare the functions we are going to use: */
  283. USHORT FileWindow();
  284. STRPTR right_pos();
  285. APTR save_file_info();
  286. BOOL file_comp();
  287. BOOL directory();
  288. BOOL last_check();
  289. BOOL new_drawer();
  290. BOOL pick_file();
  291. BOOL request_ask();
  292. void put_in();
  293. void deallocate_file_info();
  294. void change_device();
  295. void parent();
  296. void request_ok();
  297. void display_list();
  298. void connect_dir_file();
  299. void adjust_string_gadgets();
  300. void delete_file_dir();
  301.  
  302.  
  303.  
  304. extern struct IntuitionBase *IntuitionBase;
  305.  
  306. struct Window *file_window;
  307. struct IntuiMessage *my_gadget_message;
  308.  
  309.  
  310.  
  311. /* We will allocate memory, using this structure, for every file/    */
  312. /* directory we find. They will be linked to each otherer, in such a */
  313. /* way that all directories will come first (sorted alphabetically), */
  314. /* and after them will the files come (also sorted alphabetically).  */
  315. struct file_info
  316. {
  317.   BYTE name[28];          /* Name of the file/directory, 27 characters. */
  318.   BOOL directory;         /* If it is a directory.                      */
  319.   struct file_info *next; /* Pointer to the next file_info structure.   */
  320. };
  321.  
  322.  
  323. struct FileInfoBlock *file_info;
  324. struct FileLock *lock, *Lock();
  325.  
  326.  
  327. BOOL file_lock;  /* Have we locked a file?       */
  328. BOOL more_files; /* More files in the directory? */
  329. BOOL first_file; /* First file?                  */
  330.  
  331.  
  332. struct file_info *first_pointer; /* Pointing to the first structure. */
  333.  
  334.  
  335. /* The program will use a ROM-font, 80 characters wide (40 LOWRES). */
  336. /* This is to make sure that all the text will fit in nicely in the */
  337. /* window, even if the calling program is using another font.       */
  338. struct TextAttr my_font=
  339. {
  340.   "topaz.font", /* Font Name */
  341.   TOPAZ_EIGHTY, /* Font Height */
  342.   FS_NORMAL,    /* Style */
  343.   FPF_ROMFONT   /* Preferences */
  344. };
  345.  
  346.  
  347.  
  348.  
  349.  
  350. /* ********************************************************************* */
  351. /* * IntuiText structures for the requesters                           * */
  352. /* ********************************************************************* */
  353.  
  354.  
  355. struct IntuiText text_request=
  356. {
  357.   0, 2,                        /* FrontPen, BackPen */
  358.   JAM1,                        /* DrawMode */
  359.   15, 5,                       /* LewftEdge, TopEdge */
  360.   &my_font,                    /* *ITextFont */
  361.   NULL,                        /* *IText */
  362.   NULL                         /* *NextText */
  363. };
  364.  
  365.  
  366. struct IntuiText ok_request=
  367. {
  368.   0, 2,     /* FrontPen, BackPen */
  369.   JAM1,     /* DrawMode */
  370.   6, 3,     /* LewftEdge, TopEdge */
  371.   &my_font, /* *ITextFont */
  372.   "OK",     /* *IText */
  373.   NULL      /* *NextText */
  374. };
  375.  
  376.  
  377. struct IntuiText option1_request=
  378. {
  379.   0, 2,     /* FrontPen, BackPen */
  380.   JAM1,     /* DrawMode */
  381.   6, 3,     /* LewftEdge, TopEdge */
  382.   &my_font, /* *ITextFont */
  383.   NULL,     /* *IText */
  384.   NULL      /* *NextText */
  385. };
  386.  
  387.  
  388. struct IntuiText option2_request=
  389. {
  390.   0, 2,     /* FrontPen, BackPen */
  391.   JAM1,     /* DrawMode */
  392.   6, 3,     /* LewftEdge, TopEdge */
  393.   &my_font, /* *ITextFont */
  394.   NULL,     /* *IText */
  395.   NULL      /* *NextText */
  396. };
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403. /* Values for a 4-letter box: */
  404. SHORT points4[]=
  405. {
  406.    0,  0,
  407.   44,  0,
  408.   44, 14,
  409.    0, 14,
  410.    0,  0
  411. };
  412.  
  413.  
  414. /* Values for a 6-letter box: */
  415. SHORT points6[]=
  416. {
  417.    0,  0,
  418.   60,  0,
  419.   60, 14,
  420.    0, 14,
  421.    0,  0
  422. };
  423.  
  424.  
  425. /* A border for a 4-letter box: */
  426. struct Border border_text4=
  427. {
  428.   0, 0,         /* LeftEdge, TopEdge */
  429.   1, 2, JAM1,   /* FrontPen, BackPen, DrawMode */
  430.   5,            /* Count */
  431.   points4,      /* *XY */
  432.   NULL          /* *NextBorder */
  433. };
  434.  
  435.  
  436. /* A border for a 6-letter box: */
  437. struct Border border_text6=
  438. {
  439.   0, 0,         /* LeftEdge, TopEdge */
  440.   1, 2, JAM1,   /* FrontPen, BackPen, DrawMode */
  441.   5,            /* Count */
  442.   points6,      /* *XY */
  443.   NULL          /* *NextBorder */
  444. };
  445.  
  446.  
  447.  
  448. /* ********************************************************************* */
  449. /* * Information for the proportional gadget                           * */
  450. /* ********************************************************************* */
  451.  
  452. /* Since we are using the auto-knob we set GadgetRender to point to an   */
  453. /* Image. In this case we do not need to initialize the Image structure: */
  454. struct Image image_prop;
  455.  
  456. /* This is the special data required by the proportional gadget: */
  457. struct PropInfo prop_info=
  458. {
  459.   AUTOKNOB| /* We want to use the auto-knob. */
  460.   FREEVERT, /* The knob should move vertically. */
  461.   0,0,      /* HorizPot, VertPot: will be initialized later. */
  462.   0,        /* HorizBody                 -"-                 */
  463.   0xFFFF,   /* VertBody: No data to show, maximum. */
  464.   
  465.   0,0,0,0,0,0 /* Intuition sets and maintains these variables. */
  466. };
  467.  
  468. struct Gadget gadget_proportional=
  469. {
  470.   NULL,                     /* *NextGadget */
  471.   290, 50, 21, 72,          /* LeftEdge, TopEdge, Width, Height */
  472.   GADGHCOMP,                /* Flags */
  473.   GADGIMMEDIATE|FOLLOWMOUSE|RELVERIFY, /* Activation */
  474.   PROPGADGET,               /* GadgetType */
  475.   (APTR) &image_prop,       /* GadgetRender */
  476.   NULL,                     /* SelectRender */
  477.   NULL,                     /* *GadgetText */
  478.   NULL,                     /* MutualExclude */
  479.   (APTR) &prop_info,        /* SpecialInfo */
  480.   NULL,                     /* GadgetID */
  481.   NULL                      /* UserData */
  482. };
  483.  
  484.  
  485.  
  486. /* UndoBuffer for the string gadgets: */
  487. UBYTE name_backup[DRAWER_LENGTH];
  488.  
  489.  
  490.  
  491. /* ********************************************************************* */
  492. /* * Information for the string gadget "Drawer:"                       * */
  493. /* ********************************************************************* */
  494.  
  495. UBYTE drawer_name[DRAWER_LENGTH];
  496.  
  497. /* Values for a 28-letter string box: */
  498. SHORT points28s[]=
  499. {
  500.    -7, -4,
  501.   200, -4,
  502.   200, 11,
  503.    -7, 11,
  504.    -7, -4
  505. };
  506.  
  507.  
  508. /* A border for a 28-letter string box: */
  509. struct Border border_text28s=
  510. {
  511.   0, 0,         /* LeftEdge, TopEdge */
  512.   1, 2, JAM1,   /* FrontPen, BackPen, DrawMode */
  513.   5,            /* Count */
  514.   points28s,    /* *XY */
  515.   NULL          /* *NextBorder */
  516. };
  517.  
  518.  
  519. struct IntuiText text_drawer=
  520. {
  521.   1, 2,       /* FrontPen, BackPen */
  522.   JAM1,       /* DrawMode */
  523.   -69, 0,     /* LewftEdge, TopEdge */
  524.   &my_font,   /* *ITextFont */
  525.   "Drawer:",  /* *IText */
  526.   NULL        /* *NextText */
  527. };
  528.  
  529.  
  530. struct StringInfo string_drawer=
  531. {
  532.   drawer_name,        /* *Buffer */
  533.   name_backup,        /* *UndoBuffer */
  534.   0,                  /* BufferPos */
  535.   70,                 /* MaxChars (Including NULL) */
  536.   0,                  /* DispPos */
  537.  
  538.   /* Intuition initializes and maintains these variables for you: */
  539.   0,                 /* UndoPos */
  540.   0, 0,              /* CLeft, CTop */
  541.   NULL,              /* *LayerPtr */
  542.   NULL,              /* LongInt */
  543.   NULL,              /* *AltKeyMap */
  544. };
  545.  
  546.  
  547. struct Gadget gadget_drawer=
  548. {
  549.   &gadget_proportional,    /* *NextGadget */
  550.   83, 35, 198, 8,          /* LeftEdge, TopEdge, Width, Height */
  551.   GADGHCOMP,               /* Flags */
  552.   RELVERIFY,               /* Activation */
  553.   STRGADGET,               /* GadgetType */
  554.   (APTR) &border_text28s,  /* GadgetRender */
  555.   NULL,                    /* SelectRender */
  556.   &text_drawer,            /* *GadgetText */
  557.   NULL,                    /* MutualExclude */
  558.   (APTR) &string_drawer,   /* SpecialInfo */
  559.   NULL,                    /* GadgetID */
  560.   NULL                     /* UserData */
  561. };
  562.  
  563.  
  564.  
  565. /* ********************************************************************* */
  566. /* * Information for the string gadget "File:"                         * */
  567. /* ********************************************************************* */
  568.  
  569.  
  570. UBYTE file_name[FILE_LENGTH];
  571.  
  572.  
  573. /* Values for a 30-letter string box: */
  574. SHORT points30s[]=
  575. {
  576.    -7, -4,
  577.   244, -4,
  578.   244, 11,
  579.    -7, 11,
  580.    -7, -4
  581. };
  582.  
  583.  
  584. /* A border for a 30-letter string box: */
  585. struct Border border_text30s=
  586. {
  587.   0, 0,         /* LeftEdge, TopEdge */
  588.   1, 2, JAM1,   /* FrontPen, BackPen, DrawMode */
  589.   5,            /* Count */
  590.   points30s,    /* *XY */
  591.   NULL          /* *NextBorder */
  592. };
  593.  
  594.  
  595. struct IntuiText text_file=
  596. {
  597.   1, 2,     /* FrontPen, BackPen */
  598.   JAM1,     /* DrawMode */
  599.   -53, 0,   /* LewftEdge, TopEdge */
  600.   &my_font, /* *ITextFont */
  601.   "File:",  /* *IText */
  602.   NULL      /* *NextText */
  603. };
  604.  
  605.  
  606. struct StringInfo string_file=
  607. {
  608.   file_name,         /* *Buffer */
  609.   name_backup,       /* *UndoBuffer */
  610.   0,                 /* BufferPos */
  611.   40,                /* MaxChars (Including NULL) */
  612.   0,                 /* DispPos */
  613.   
  614.   /* Intuition initializes and maintains these variables for you: */
  615.   0,                 /* UndoPos */
  616.   0, 0,              /* CLeft, CTop */
  617.   NULL,              /* *LayerPtr */
  618.   NULL,              /* LongInt */
  619.   NULL,              /* *AltKeyMap */
  620. };
  621.  
  622.  
  623. struct Gadget gadget_file=
  624. {
  625.   &gadget_drawer,         /* *NextGadget */
  626.   66, 129, 240, 8,        /* LeftEdge, TopEdge, Width, Height */
  627.   GADGHCOMP,              /* Flags */
  628.   NULL,                   /* Activation */
  629.   STRGADGET,              /* GadgetType */
  630.   (APTR) &border_text30s, /* GadgetRender */
  631.   NULL,                   /* SelectRender */
  632.   &text_file,             /* *GadgetText */
  633.   NULL,                   /* MutualExclude */
  634.   (APTR) &string_file,    /* SpecialInfo */
  635.   NULL,                   /* GadgetID */
  636.   NULL                    /* UserData */
  637. };
  638.  
  639.  
  640.  
  641. /* ********************************************************************* */
  642. /* * Information for the string gadget "Extension"                     * */
  643. /* ********************************************************************* */
  644.  
  645.  
  646. UBYTE extension_name[7]; /* 7 characters including NULL. */
  647.  
  648.  
  649. /* Values for a 6-letter string box: */
  650. SHORT points6s[]=
  651. {
  652.   -7, -4,
  653.   57, -4,
  654.   57, 10,
  655.   -7, 10,
  656.   -7, -4
  657. };
  658.  
  659.  
  660. /* A border for a 6-letter string box: */
  661. struct Border border_text6s=
  662. {
  663.   0, 0,         /* LeftEdge, TopEdge */
  664.   1, 2, JAM1,   /* FrontPen, BackPen, DrawMode */
  665.   5,            /* Count */
  666.   points6s,     /* *XY */
  667.   NULL          /* *NextBorder */
  668. };
  669.  
  670.  
  671. struct IntuiText text_extension=
  672. {
  673.   1, 2,     /* FrontPen, BackPen */
  674.   JAM1,     /* DrawMode */
  675.   -45, 0,   /* LewftEdge, TopEdge */
  676.   &my_font, /* *ITextFont */
  677.   "Ext:",   /* *IText */
  678.   NULL      /* *NextText */
  679. };
  680.  
  681.  
  682. struct StringInfo string_extension=
  683. {
  684.   extension_name,    /* *Buffer */
  685.   name_backup,       /* *UndoBuffer */
  686.   0,                 /* BufferPos */
  687.   7,                 /* MaxChars (Including NULL) */
  688.   0,                 /* DispPos */
  689.   
  690.   /* Intuition initializes and maintains these variables for you: */
  691.   0,                 /* UndoPos */
  692.   0, 0,              /* CLeft, CTop */
  693.   NULL,              /* *LayerPtr */
  694.   NULL,              /* LongInt */
  695.   NULL,              /* *AltKeyMap */
  696. };
  697.  
  698.  
  699. struct Gadget gadget_extension=
  700. {
  701.   &gadget_file,             /* *NextGadget */
  702.   253, 17, 59, 8,           /* LeftEdge, TopEdge, Width, Height */
  703.   GADGHCOMP,                /* Flags */
  704.   RELVERIFY,                /* Activation */
  705.   STRGADGET,                /* GadgetType */
  706.   (APTR) &border_text6s,    /* GadgetRender */
  707.   NULL,                     /* SelectRender */
  708.   &text_extension,          /* *GadgetText */
  709.   NULL,                     /* MutualExclude */
  710.   (APTR) &string_extension, /* SpecialInfo */
  711.   NULL,                     /* GadgetID */
  712.   NULL                      /* UserData */
  713. };
  714.  
  715.  
  716.  
  717. /* ********************************************************************* */
  718. /* * Information for the boolean gadget parent "<"                     * */
  719. /* ********************************************************************* */
  720.  
  721.  
  722. /* Values for a 1-letter box: */
  723. SHORT points1[]=
  724. {
  725.    0,  0,
  726.   20,  0,
  727.   20, 15,
  728.    0, 15,
  729.    0,  0
  730. };
  731.  
  732.  
  733. /* A border for a 1-letter box: */
  734. struct Border border_text1=
  735. {
  736.   0, 0,         /* LeftEdge, TopEdge */
  737.   1, 2, JAM1,   /* FrontPen, BackPen, DrawMode */
  738.   5,            /* Count */
  739.   points1,      /* *XY */
  740.   NULL          /* *NextBorder */
  741. };
  742.  
  743.  
  744. struct IntuiText text_parent=
  745. {
  746.   1, 2,     /* FrontPen, BackPen */
  747.   JAM1,     /* DrawMode */
  748.   7,4,      /* LeftEdge, TopEdge */
  749.   &my_font, /* *ITextFont, (Topaz, 80) */
  750.   "<",      /* *IText */
  751.   NULL      /* *NextText */
  752. };
  753.  
  754.  
  755. struct Gadget gadget_parent=
  756. {
  757.   &gadget_extension,      /* *NextGadget */
  758.   290, 31, 21, 16,        /* LeftEdge, TopEdge, Width, Height */
  759.   GADGHCOMP,              /* Flags */
  760.   RELVERIFY,              /* Activation */
  761.   BOOLGADGET,             /* GadgetType */
  762.   (APTR) &border_text1,   /* GadgetRender */
  763.   NULL,                   /* SelectRender */
  764.   &text_parent,           /* *GadgetText */
  765.   NULL,                   /* MutualExclude */
  766.   NULL,                   /* SpecialInfo */
  767.   NULL,                   /* GadgetID */
  768.   NULL                    /* UserData */
  769. };
  770.  
  771.  
  772.  
  773. /* ********************************************************************* */
  774. /* * Information for the boolean gadget "dh0:"                         * */
  775. /* ********************************************************************* */
  776.  
  777.  
  778. struct IntuiText text_dh0=
  779. {
  780.   1, 2,     /* FrontPen, BackPen */
  781.   JAM1,     /* DrawMode */
  782.   7,4,      /* LeftEdge, TopEdge */
  783.   &my_font, /* *ITextFont, (Topaz, 80) */
  784.   "dh0:",   /* *IText */
  785.   NULL      /* *NextText */
  786. };
  787.  
  788.  
  789. struct Gadget gadget_dh0=
  790. {
  791.   &gadget_parent,         /* *NextGadget */
  792.   110, 13, 45, 15,        /* LeftEdge, TopEdge, Width, Height */
  793.   GADGHCOMP,              /* Flags */
  794.   RELVERIFY,              /* Activation */
  795.   BOOLGADGET,             /* GadgetType */
  796.   (APTR) &border_text4,   /* GadgetRender */
  797.   NULL,                   /* SelectRender */
  798.   &text_dh0,              /* *GadgetText */
  799.   NULL,                   /* MutualExclude */
  800.   NULL,                   /* SpecialInfo */
  801.   NULL,                   /* GadgetID */
  802.   NULL                    /* UserData */
  803. };
  804.  
  805.  
  806.  
  807. /* ********************************************************************* */
  808. /* * Information for the boolean gadget "df1:"                         * */
  809. /* ********************************************************************* */
  810.  
  811.  
  812. struct IntuiText text_df1=
  813. {
  814.   1, 2,     /* FrontPen, BackPen */
  815.   JAM1,     /* DrawMode */
  816.   7,4,      /* LeftEdge, TopEdge */
  817.   &my_font, /* *ITextFont, (Topaz, 80) */
  818.   "df1:",   /* *IText */
  819.   NULL      /* *NextText */
  820. };
  821.  
  822.  
  823. struct Gadget gadget_df1=
  824. {
  825.   &gadget_dh0,            /* *NextGadget */
  826.   59, 13, 45, 15,         /* LeftEdge, TopEdge, Width, Height */
  827.   GADGHCOMP,              /* Flags */
  828.   RELVERIFY,              /* Activation */
  829.   BOOLGADGET,             /* GadgetType */
  830.   (APTR) &border_text4,   /* GadgetRender */
  831.   NULL,                   /* SelectRender */
  832.   &text_df1,              /* *GadgetText */
  833.   NULL,                   /* MutualExclude */
  834.   NULL,                   /* SpecialInfo */
  835.   NULL,                   /* GadgetID */
  836.   NULL                    /* UserData */
  837. };
  838.  
  839.  
  840.  
  841. /* ********************************************************************* */
  842. /* * Information for the boolean gadget "df0:"                         * */
  843. /* ********************************************************************* */
  844.  
  845.  
  846. struct IntuiText text_df0=
  847. {
  848.   1, 2,     /* FrontPen, BackPen */
  849.   JAM1,     /* DrawMode */
  850.   7,4,      /* LeftEdge, TopEdge */
  851.   &my_font, /* *ITextFont, (Topaz, 80) */
  852.   "df0:",   /* *IText */
  853.   NULL      /* *NextText */
  854. };
  855.  
  856.  
  857. struct Gadget gadget_df0=
  858. {
  859.   &gadget_df1,            /* *NextGadget */
  860.   8, 13, 45, 15,          /* LeftEdge, TopEdge, Width, Height */
  861.   GADGHCOMP,              /* Flags */
  862.   RELVERIFY,              /* Activation */
  863.   BOOLGADGET,             /* GadgetType */
  864.   (APTR) &border_text4,   /* GadgetRender */
  865.   NULL,                   /* SelectRender */
  866.   &text_df0,              /* *GadgetText */
  867.   NULL,                   /* MutualExclude */
  868.   NULL,                   /* SpecialInfo */
  869.   NULL,                   /* GadgetID */
  870.   NULL                    /* UserData */
  871. };
  872.  
  873.  
  874.  
  875. /* ********************************************************************* */
  876. /* * Information for the boolean gadget "CANCEL"                       * */
  877. /* ********************************************************************* */
  878.  
  879.  
  880. struct IntuiText text_cancel=
  881. {
  882.   1, 2,     /* FrontPen, BackPen */
  883.   JAM1,     /* DrawMode */
  884.   7,4,      /* LeftEdge, TopEdge */
  885.   &my_font, /* *ITextFont, (Topaz, 80) */
  886.   "CANCEL", /* *IText */
  887.   NULL      /* *NextText */
  888. };
  889.  
  890.  
  891. struct Gadget gadget_cancel=
  892. {
  893.   &gadget_df0,            /* *NextGadget */
  894.   177, 144, 61, 15,       /* LeftEdge, TopEdge, Width, Height */
  895.   GADGHCOMP,              /* Flags */
  896.   RELVERIFY,              /* Activation */
  897.   BOOLGADGET,             /* GadgetType */
  898.   (APTR) &border_text6,   /* GadgetRender */
  899.   NULL,                   /* SelectRender */
  900.   &text_cancel,           /* *GadgetText */
  901.   NULL,                   /* MutualExclude */
  902.   NULL,                   /* SpecialInfo */
  903.   NULL,                   /* GadgetID */
  904.   NULL                    /* UserData */
  905. };
  906.  
  907.  
  908.  
  909. /* ********************************************************************* */
  910. /* * Information for the boolean gadget "DELETE"                       * */
  911. /* ********************************************************************* */
  912.  
  913.  
  914. struct IntuiText text_delete=
  915. {
  916.   1, 2,     /* FrontPen, BackPen */
  917.   JAM1,     /* DrawMode */
  918.   7,4,      /* LeftEdge, TopEdge */
  919.   &my_font, /* *ITextFont, (Topaz, 80) */
  920.   "DELETE", /* *IText */
  921.   NULL      /* *NextText */
  922. };
  923.  
  924.  
  925. struct Gadget gadget_delete=
  926. {
  927.   &gadget_cancel,         /* *NextGadget */
  928.   110, 144, 61, 15,       /* LeftEdge, TopEdge, Width, Height */
  929.   GADGHCOMP,              /* Flags */
  930.   RELVERIFY,              /* Activation */
  931.   BOOLGADGET,             /* GadgetType */
  932.   (APTR) &border_text6,   /* GadgetRender */
  933.   NULL,                   /* SelectRender */
  934.   &text_delete,           /* *GadgetText */
  935.   NULL,                   /* MutualExclude */
  936.   NULL,                   /* SpecialInfo */
  937.   NULL,                   /* GadgetID */
  938.   NULL                    /* UserData */
  939. };
  940.  
  941.  
  942.  
  943. /* ********************************************************************* */
  944. /* * Information for the boolean gadget "SAVE"                         * */
  945. /* ********************************************************************* */
  946.  
  947.  
  948. struct IntuiText text_save=
  949. {
  950.   1, 2,     /* FrontPen, BackPen */
  951.   JAM1,     /* DrawMode */
  952.   7,4,      /* LeftEdge, TopEdge */
  953.   &my_font, /* *ITextFont, (Topaz, 80) */
  954.   "SAVE",   /* *IText */
  955.   NULL      /* *NextText */
  956. };
  957.  
  958.  
  959. struct Gadget gadget_save=
  960. {
  961.   &gadget_delete,         /* *NextGadget */
  962.   59, 144, 45, 15,        /* LeftEdge, TopEdge, Width, Height */
  963.   GADGHCOMP,              /* Flags */
  964.   RELVERIFY,              /* Activation */
  965.   BOOLGADGET,             /* GadgetType */
  966.   (APTR) &border_text4,   /* GadgetRender */
  967.   NULL,                   /* SelectRender */
  968.   &text_save,             /* *GadgetText */
  969.   NULL,                   /* MutualExclude */
  970.   NULL,                   /* SpecialInfo */
  971.   NULL,                   /* GadgetID */
  972.   NULL                    /* UserData */
  973. };
  974.  
  975.  
  976.  
  977. /* ********************************************************************* */
  978. /* * Information for the boolean gadget "LOAD"                         * */
  979. /* ********************************************************************* */
  980.  
  981.  
  982. struct IntuiText text_load=
  983. {
  984.   1, 2,     /* FrontPen, BackPen */
  985.   JAM1,     /* DrawMode */
  986.   7,4,      /* LeftEdge, TopEdge */
  987.   &my_font, /* *ITextFont, (Topaz, 80) */
  988.   "LOAD",   /* *IText */
  989.   NULL      /* *NextText */
  990. };
  991.  
  992.  
  993. struct Gadget gadget_load=
  994. {
  995.   &gadget_save,           /* *NextGadget */
  996.   8, 144, 45, 15,         /* LeftEdge, TopEdge, Width, Height */
  997.   GADGHCOMP,              /* Flags */
  998.   RELVERIFY,              /* Activation */
  999.   BOOLGADGET,             /* GadgetType */
  1000.   (APTR) &border_text4,   /* GadgetRender */
  1001.   NULL,                   /* SelectRender */
  1002.   &text_load,             /* *GadgetText */
  1003.   NULL,                   /* MutualExclude */
  1004.   NULL,                   /* SpecialInfo */
  1005.   NULL,                   /* GadgetID */
  1006.   NULL                    /* UserData */
  1007. };
  1008.  
  1009.  
  1010.  
  1011. UBYTE display_text[8][34];
  1012.  
  1013. struct IntuiText text_list[8]=
  1014. {
  1015.   {
  1016.     1, 0,            /* FrontPen, BackPen */
  1017.     JAM2,            /* DrawMode */
  1018.     0,0,             /* LeftEdge, TopEdge */
  1019.     &my_font,        /* *ITextFont */
  1020.     display_text[0], /* IText */
  1021.     &text_list[1]    /* *NextText */
  1022.   },
  1023.   {
  1024.     1, 0,            /* FrontPen, BackPen */
  1025.     JAM2,            /* DrawMode */
  1026.     0,8,             /* LeftEdge, TopEdge */
  1027.     &my_font,        /* *ITextFont */
  1028.     display_text[1], /* IText */
  1029.     &text_list[2]    /* *NextText */
  1030.   },
  1031.   {
  1032.     1, 0,            /* FrontPen, BackPen */
  1033.     JAM2,            /* DrawMode */
  1034.     0,16,            /* LeftEdge, TopEdge */
  1035.     &my_font,        /* *ITextFont */
  1036.     display_text[2], /* IText */
  1037.     &text_list[3]    /* *NextText */
  1038.   },
  1039.   {
  1040.     1, 0,            /* FrontPen, BackPen */
  1041.     JAM2,            /* DrawMode */
  1042.     0,24,            /* LeftEdge, TopEdge */
  1043.     &my_font,        /* *ITextFont */
  1044.     display_text[3], /* IText */
  1045.     &text_list[4]    /* *NextText */
  1046.   },
  1047.   {
  1048.     1, 0,            /* FrontPen, BackPen */
  1049.     JAM2,            /* DrawMode */
  1050.     0,32,            /* LeftEdge, TopEdge */
  1051.     &my_font,        /* *ITextFont */
  1052.     display_text[4], /* IText */
  1053.     &text_list[5]    /* *NextText */
  1054.   },
  1055.   {
  1056.     1, 0,            /* FrontPen, BackPen */
  1057.     JAM2,            /* DrawMode */
  1058.     0,40,            /* LeftEdge, TopEdge */
  1059.     &my_font,        /* *ITextFont */
  1060.     display_text[5], /* IText */
  1061.     &text_list[6]    /* *NextText */
  1062.   },
  1063.   {
  1064.     1, 0,            /* FrontPen, BackPen */
  1065.     JAM2,            /* DrawMode */
  1066.     0,48,            /* LeftEdge, TopEdge */
  1067.     &my_font,        /* *ITextFont */
  1068.     display_text[6], /* IText */
  1069.     &text_list[7]    /* *NextText */
  1070.   },
  1071.   {
  1072.     1, 0,            /* FrontPen, BackPen */
  1073.     JAM2,            /* DrawMode */
  1074.     0,56,            /* LeftEdge, TopEdge */
  1075.     &my_font,        /* *ITextFont */
  1076.     display_text[7], /* IText */
  1077.     NULL             /* *NextText */
  1078.   }
  1079. };
  1080.  
  1081.  
  1082.  
  1083. struct Gadget gadget_display[8]=
  1084. {
  1085.   {
  1086.     &gadget_display[1], /* *NextGadget */
  1087.     8, 50, 276, 12,     /* LeftEdge, TopEdge, Width, Height */
  1088.     GADGHNONE,          /* Flags */
  1089.     GADGIMMEDIATE,      /* Activation */
  1090.     BOOLGADGET,         /* GadgetType */
  1091.     NULL,               /* GadgetRender */
  1092.     NULL,               /* SelectRender */
  1093.     NULL,               /* *GadgetText */
  1094.     NULL,               /* MutualExclude */
  1095.     NULL,               /* SpecialInfo */
  1096.     NULL,               /* GadgetID */
  1097.     NULL                /* UserData */
  1098.   },
  1099.   {
  1100.     &gadget_display[2], /* *NextGadget */
  1101.     8, 62, 276, 8,      /* LeftEdge, TopEdge, Width, Height */
  1102.     GADGHNONE,          /* Flags */
  1103.     GADGIMMEDIATE,      /* Activation */
  1104.     BOOLGADGET,         /* GadgetType */
  1105.     NULL,               /* GadgetRender */
  1106.     NULL,               /* SelectRender */
  1107.     NULL,               /* *GadgetText */
  1108.     NULL,               /* MutualExclude */
  1109.     NULL,               /* SpecialInfo */
  1110.     NULL,               /* GadgetID */
  1111.     NULL                /* UserData */
  1112.   },
  1113.   {
  1114.     &gadget_display[3], /* *NextGadget */
  1115.     8, 70, 276, 8,      /* LeftEdge, TopEdge, Width, Height */
  1116.     GADGHNONE,          /* Flags */
  1117.     GADGIMMEDIATE,      /* Activation */
  1118.     BOOLGADGET,         /* GadgetType */
  1119.     NULL,               /* GadgetRender */
  1120.     NULL,               /* SelectRender */
  1121.     NULL,               /* *GadgetText */
  1122.     NULL,               /* MutualExclude */
  1123.     NULL,               /* SpecialInfo */
  1124.     NULL,               /* GadgetID */
  1125.     NULL                /* UserData */
  1126.   },
  1127.   {
  1128.     &gadget_display[4], /* *NextGadget */
  1129.     8, 78, 276, 8,      /* LeftEdge, TopEdge, Width, Height */
  1130.     GADGHNONE,          /* Flags */
  1131.     GADGIMMEDIATE,      /* Activation */
  1132.     BOOLGADGET,         /* GadgetType */
  1133.     NULL,               /* GadgetRender */
  1134.     NULL,               /* SelectRender */
  1135.     NULL,               /* *GadgetText */
  1136.     NULL,               /* MutualExclude */
  1137.     NULL,               /* SpecialInfo */
  1138.     NULL,               /* GadgetID */
  1139.     NULL                /* UserData */
  1140.   },
  1141.   {
  1142.     &gadget_display[5], /* *NextGadget */
  1143.     8, 86, 276, 8,      /* LeftEdge, TopEdge, Width, Height */
  1144.     GADGHNONE,          /* Flags */
  1145.     GADGIMMEDIATE,      /* Activation */
  1146.     BOOLGADGET,         /* GadgetType */
  1147.     NULL,               /* GadgetRender */
  1148.     NULL,               /* SelectRender */
  1149.     NULL,               /* *GadgetText */
  1150.     NULL,               /* MutualExclude */
  1151.     NULL,               /* SpecialInfo */
  1152.     NULL,               /* GadgetID */
  1153.     NULL                /* UserData */
  1154.   },
  1155.   {
  1156.     &gadget_display[6], /* *NextGadget */
  1157.     8, 94, 276, 8,      /* LeftEdge, TopEdge, Width, Height */
  1158.     GADGHNONE,          /* Flags */
  1159.     GADGIMMEDIATE,      /* Activation */
  1160.     BOOLGADGET,         /* GadgetType */
  1161.     NULL,               /* GadgetRender */
  1162.     NULL,               /* SelectRender */
  1163.     NULL,               /* *GadgetText */
  1164.     NULL,               /* MutualExclude */
  1165.     NULL,               /* SpecialInfo */
  1166.     NULL,               /* GadgetID */
  1167.     NULL                /* UserData */
  1168.   },
  1169.   {
  1170.     &gadget_display[7], /* *NextGadget */
  1171.     8, 102, 276, 8,      /* LeftEdge, TopEdge, Width, Height */
  1172.     GADGHNONE,          /* Flags */
  1173.     GADGIMMEDIATE,      /* Activation */
  1174.     BOOLGADGET,         /* GadgetType */
  1175.     NULL,               /* GadgetRender */
  1176.     NULL,               /* SelectRender */
  1177.     NULL,               /* *GadgetText */
  1178.     NULL,               /* MutualExclude */
  1179.     NULL,               /* SpecialInfo */
  1180.     NULL,               /* GadgetID */
  1181.     NULL                /* UserData */
  1182.   },
  1183.   {
  1184.     &gadget_load,       /* *NextGadget */
  1185.     8, 110, 276, 12,    /* LeftEdge, TopEdge, Width, Height */
  1186.     GADGHNONE,          /* Flags */
  1187.     GADGIMMEDIATE,      /* Activation */
  1188.     BOOLGADGET,         /* GadgetType */
  1189.     NULL,               /* GadgetRender */
  1190.     NULL,               /* SelectRender */
  1191.     NULL,               /* *GadgetText */
  1192.     NULL,               /* MutualExclude */
  1193.     NULL,               /* SpecialInfo */
  1194.     NULL,               /* GadgetID */
  1195.     NULL                /* UserData */
  1196.   }
  1197. };
  1198.  
  1199.  
  1200.  
  1201. /* ********************************************************************* */
  1202. /* * BIG BOX                                                           * */
  1203. /* ********************************************************************* */
  1204.  
  1205.  
  1206. /* Values for a big box: */
  1207. SHORT points_big_box[]=
  1208. {
  1209.    8, 50,
  1210.  283, 50,
  1211.  283, 121,
  1212.    8, 121,
  1213.    8, 50
  1214. };
  1215.  
  1216.  
  1217. /* A border for a 1-letter box: */
  1218. struct Border border_big_box=
  1219. {
  1220.   0, 0,           /* LeftEdge, TopEdge */
  1221.   1, 2, JAM1,     /* FrontPen, BackPen, DrawMode */
  1222.   5,              /* Count */
  1223.   points_big_box, /* *XY */
  1224.   NULL            /* *NextBorder */
  1225. };
  1226.  
  1227.  
  1228.  
  1229. /* ********************************************************************* */
  1230. /* * Information for the window                                          */
  1231. /* ********************************************************************* */
  1232.  
  1233. struct NewWindow new_file_window=
  1234. {
  1235.   0,0,              /* LeftEdge, TopEdge */
  1236.   320, 163,         /* Width, Height */
  1237.   0,1,              /* DetailPen, BlockPen */
  1238.  
  1239.   CLOSEWINDOW|      /* IDCMPFlags */
  1240.   GADGETDOWN|
  1241.   MOUSEMOVE|
  1242.   GADGETUP,
  1243.  
  1244.   ACTIVATE|         /* Flags */
  1245.   WINDOWDEPTH|
  1246.   WINDOWDRAG|
  1247.   WINDOWCLOSE|
  1248.   SMART_REFRESH,
  1249.  
  1250.   &gadget_display[0], /* *FirstGadget */
  1251.   NULL,               /* *CheckMark */
  1252.   NULL,               /* *Title */
  1253.   NULL,               /* *Screen */
  1254.   NULL,               /* *BitMap */
  1255.   0,0,                /* MinWidth, MinHeight */
  1256.   0,0,                /* MaxWidth, MaxHeight */
  1257.   WBENCHSCREEN        /* Type */
  1258. };
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274. USHORT FileWindow( title, extension, x, y, screen, total_file_name )
  1275. STRPTR title;
  1276. STRPTR extension;
  1277. SHORT  x,y;
  1278. struct Screen *screen;
  1279. STRPTR total_file_name;
  1280. {
  1281.   int temp1; /* Variable used for loops etc. */
  1282.   int file_count; /* How many files/directories there are. */
  1283.  
  1284.   ULONG class;  /* Saved IntuiMessage: IDCMP flags. */
  1285.   USHORT code;  /*        -"-        : Special code. */
  1286.   APTR address; /*        -"-        : The address of the object. */
  1287.  
  1288.   int position; /* The number of the first file in the display. */
  1289.  
  1290.   BOOL working;     /* Wants the user to quit? */
  1291.   BOOL fix_display; /* Should we update the file-display? */
  1292.  
  1293.   STRPTR string_pointer; /* Pointer to a string. */
  1294.   struct file_info *pointer; /* Pointer to a file_info structure. */
  1295.  
  1296.   USHORT operation; /* What operation FileWindow will return. */
  1297.   
  1298.  
  1299.   file_lock=FALSE; /* We have not locked any file/directory. */
  1300.   more_files=FALSE; /* Do not list any files yet. */
  1301.  
  1302.  
  1303.   /* Make sure the proportional gadget is at the top, showing 100%: */
  1304.   prop_info.VertBody=0xFFFF;
  1305.   prop_info.HorizBody=0;
  1306.   prop_info.VertPot=0;
  1307.   prop_info.HorizPot=0;
  1308.   
  1309.  
  1310.   /* Copy the extension into the string gadget: */
  1311.   strcpy(extension_name, extension);
  1312.  
  1313.   /* If there is an extension, the text "Ext:" will be highlighted: */
  1314.   if(*extension_name != '\0')
  1315.     text_extension.FrontPen=3; /* Orange. (Normal WB colour) */
  1316.   else
  1317.     text_extension.FrontPen=1; /* White. (Normal WB colour) */
  1318.  
  1319.  
  1320.   /* Change some values in the new_file_window structure: */
  1321.   new_file_window.LeftEdge=x;
  1322.   new_file_window.TopEdge=y;
  1323.   new_file_window.Title=title;
  1324.  
  1325.   /* Does the user want to use on of his own screens? */
  1326.   if(screen)
  1327.   {
  1328.     new_file_window.Screen=screen;
  1329.     new_file_window.Type=CUSTOMSCREEN;
  1330.   }    
  1331.  
  1332.  
  1333.   /* Open the window: */
  1334.   if( (file_window = (struct Window *) OpenWindow(&new_file_window)) == NULL )
  1335.   {
  1336.     /* We could NOT open the window! */
  1337.   
  1338.     /* Leave: */
  1339.     return(PANIC);
  1340.   }
  1341.  
  1342.  
  1343.   /* Draw the big box around the display: */
  1344.   DrawBorder(file_window->RPort, &border_big_box, 0, 0);
  1345.  
  1346.  
  1347.  
  1348.  
  1349.   /* Allocate memory for the FileInfoBlock: */
  1350.   if((file_info=(struct FileInfoBlock *)
  1351.     AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  1352.   {
  1353.     /* Could not allocate memory for the FileInfoBlock! */
  1354.     /* Inform the user about the problem, and leave. */
  1355.     request_ok("NOT enough memory!");
  1356.     return(PANIC);
  1357.   }
  1358.  
  1359.  
  1360.   /* Is the there anything in the total_file_name string? */
  1361.   if(*total_file_name != '\0')
  1362.   {
  1363.     /* Yes! */
  1364.     /* Try to "lock" the file/directory: */
  1365.     if((lock=Lock(total_file_name, ACCESS_READ))==NULL)
  1366.     {
  1367.       /* PROBLEMS! */
  1368.       /* File/directory/device did NOT exist! */
  1369.     }
  1370.     else
  1371.     {
  1372.       /* Could lock the file/directory! */
  1373.       file_lock=TRUE;
  1374.   
  1375.       /* Get some information of the file/directory: */
  1376.       if((Examine(lock, file_info))==NULL)
  1377.       {
  1378.         /* Could NOT examine the object! */
  1379.         request_ok("ERROR reading file/directory!");
  1380.       }
  1381.       else
  1382.       {
  1383.         /* Is it a directory or a file? */
  1384.         if(directory(file_info))
  1385.         {
  1386.           /* It is a directory! */
  1387.  
  1388.           *file_name='\0'; /* Clear file_name string. */
  1389.           /* Copy total_file_name into drawer_name string: */
  1390.           strcpy(drawer_name, total_file_name);
  1391.  
  1392.           /* Since it is a directory, we will look for more files: */
  1393.           more_files=TRUE;
  1394.         }
  1395.         else
  1396.         {
  1397.           /* It is a file! */
  1398.           
  1399.           /* Separate the file name from the path: */
  1400.           if(string_pointer=right_pos(total_file_name, '/'))
  1401.           {
  1402.             /* Copy the file name into file_name string: */
  1403.             strcpy(file_name, string_pointer+1);
  1404.             *string_pointer='\0';
  1405.           }
  1406.           else
  1407.           {
  1408.             if(string_pointer=right_pos(total_file_name, ':'))
  1409.             {
  1410.               /* Copy the file name into file_name string: */
  1411.               strcpy(file_name, string_pointer+1);
  1412.               *(string_pointer+1)='\0';
  1413.             }
  1414.             else
  1415.             {
  1416.               strcpy(file_name, total_file_name);        
  1417.               *drawer_name='\0';
  1418.               *total_file_name='\0';
  1419.             }
  1420.           }
  1421.           strcpy(drawer_name, total_file_name);
  1422.  
  1423.           /* Since it is a file, we will NOT look for more files: */
  1424.           /* However, more_files is already FALSE. */
  1425.  
  1426.         } /* Is it a directory? */
  1427.  
  1428.       } /* Could we examine the object? */
  1429.  
  1430.     } /* Could we "lock" the file/directory? */
  1431.  
  1432.   } /* Anything in the total_file_name string? */
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.   /* Since we have messed around with the string gadgets it is best */
  1440.   /* to adjust them so the user can see them clearly:               */
  1441.   adjust_string_gadgets();
  1442.  
  1443.  
  1444.   new_drawer(); /* Start to show us the files. */
  1445.  
  1446.  
  1447.   position=0;        /* The display will show the first file. */
  1448.   fix_display=FALSE; /* We do not need to fix the display. */
  1449.   first_file=TRUE;   /* No files saved. */
  1450.   file_count=0;      /* No files saved. */
  1451.  
  1452.  
  1453.   working=TRUE;
  1454.   do
  1455.   {
  1456.     /* If we have shown all files in the directory, we put our task */
  1457.     /* to sleep. That will speed up other programs, and we will not */
  1458.     /* use unnecessary processing time:                             */
  1459.     if(more_files==FALSE)
  1460.       Wait(1 << file_window->UserPort->mp_SigBit);
  1461.  
  1462.  
  1463.     /* Has something has happened with the gadgets in the file_window? */
  1464.     while(my_gadget_message = (struct IntuiMessage *)
  1465.       GetMsg(file_window->UserPort))
  1466.     {
  1467.       /* As long as something is happening with the gadgets we will     */
  1468.       /* stay in the while loop. This is very handy since we can        */
  1469.       /* recieve hundereds of messages if the mouse is moving, and      */
  1470.       /* we only want to update the display when the mouse has stopped: */
  1471.       
  1472.       /* Collect some interesting values: */
  1473.       class = my_gadget_message->Class;
  1474.       code = my_gadget_message->Code;
  1475.       address = my_gadget_message->IAddress;
  1476.  
  1477.       /* We have now saved some important values, and can now reply: */
  1478.       /* (Do NEVER try to get some values after you have replied!)   */
  1479.       ReplyMsg((struct Message *)my_gadget_message);
  1480.  
  1481.  
  1482.       /* What has actually happened? */
  1483.       switch(class)
  1484.       {
  1485.         case MOUSEMOVE:
  1486.           /* The proportional gadget is selected, and the mouse is  */ 
  1487.           /* moving; we must update the file_display when the mouse */
  1488.           /* has stopped: */
  1489.           fix_display=TRUE;
  1490.           break;
  1491.  
  1492.         case CLOSEWINDOW:
  1493.           /* The user wants to quit. */
  1494.           connect_dir_file(total_file_name);
  1495.           working=FALSE;
  1496.           operation=QUIT;
  1497.           break;
  1498.  
  1499.         case GADGETDOWN:
  1500.            /* A gadget has been pressed down. */
  1501.            /* Which gadget has been clicked on? */
  1502.            
  1503.            /* DISPLAY */
  1504.            /* Is the user clicking inside the file display? */
  1505.            for(temp1=0; temp1 < 8; temp1++)
  1506.            {
  1507.              if(address == (APTR)&gadget_display[temp1])
  1508.              {
  1509.                /* The user wants to select a file/directory: */
  1510.                pick_file(temp1+position);
  1511.              }
  1512.            }
  1513.            break;
  1514.  
  1515.  
  1516.  
  1517.         case GADGETUP:
  1518.            /* A gadget has been released. */
  1519.            /* Which gadget has been clicked on? */
  1520.  
  1521.  
  1522.            /* LOAD */
  1523.            if(address == (APTR)&gadget_load)
  1524.            {
  1525.              if(last_check(total_file_name))
  1526.              {
  1527.                working=FALSE;
  1528.                operation=LOAD;
  1529.              }
  1530.              break;
  1531.            }
  1532.  
  1533.  
  1534.            /* SAVE */
  1535.            if(address == (APTR)&gadget_save)
  1536.            {
  1537.              if(last_check(total_file_name))
  1538.              {
  1539.                working=FALSE;
  1540.                operation=SAVE;
  1541.              }
  1542.              break;
  1543.            }
  1544.  
  1545.  
  1546.            /* DELETE */
  1547.            if(address == (APTR)&gadget_delete)
  1548.            {
  1549.              delete_file_dir(total_file_name);
  1550.              break;
  1551.            }
  1552.  
  1553.  
  1554.            /* CANCEL */
  1555.            if(address == (APTR)&gadget_cancel)
  1556.            {
  1557.              connect_dir_file(total_file_name);
  1558.              working=FALSE;
  1559.              operation=CANCEL;
  1560.              break;
  1561.            }
  1562.  
  1563.  
  1564.            /* df0: */
  1565.            if(address == (APTR)&gadget_df0)
  1566.            {
  1567.              change_device("df0:");
  1568.              break;
  1569.            }
  1570.  
  1571.  
  1572.            /* df1: */
  1573.            if(address == (APTR)&gadget_df1)
  1574.            {
  1575.              change_device("df1:");
  1576.              break;
  1577.            }
  1578.  
  1579.  
  1580.            /* dh0: */
  1581.            if(address == (APTR)&gadget_dh0)
  1582.            {
  1583.              change_device("dh0:");
  1584.              break;
  1585.            }
  1586.  
  1587.  
  1588.            /* DRAWER: */
  1589.            if(address == (APTR)&gadget_drawer)
  1590.            {
  1591.              /* The user has entered something new in the drawer: */
  1592.              new_drawer();
  1593.              break;
  1594.            }
  1595.  
  1596.  
  1597.            /* EXTENSION: */
  1598.            if(address == (APTR)&gadget_extension)
  1599.            {
  1600.              /* If there is an extension, the text "Ext:" will be */
  1601.              /* highlighted: */
  1602.              if(*extension_name != '\0')
  1603.                text_extension.FrontPen=3; /* Orange. (Normal WB colour) */
  1604.              else
  1605.                text_extension.FrontPen=1; /* White. (Normal WB colour) */
  1606.  
  1607.              /* Show the user the colour change: */
  1608.              RefreshGadgets(&gadget_extension, file_window, NULL);
  1609.  
  1610.              /* Start again to diplay the files, using a new extension. */
  1611.              new_drawer();
  1612.              break;
  1613.            }
  1614.  
  1615.  
  1616.            /* PARENT: "<" */
  1617.            if(address == (APTR)&gadget_parent)
  1618.            {
  1619.              parent();
  1620.              break;
  1621.            }
  1622.  
  1623.  
  1624.            /* PROPORTIONAL */
  1625.            if(address == (APTR)&gadget_proportional)
  1626.            {
  1627.              /* The user has released the proprtional gadget, update */
  1628.              /* the display: */
  1629.              fix_display=TRUE;
  1630.              break;
  1631.            }
  1632.       }
  1633.     }
  1634.  
  1635.  
  1636.     /* Do we need to update the file display? */
  1637.     if(fix_display)
  1638.     {
  1639.       fix_display=FALSE;
  1640.  
  1641.       /* Which file should we start to show in the display? */
  1642.       if(file_count > 8)
  1643.         position=(int) prop_info.VertPot/(float) 0xFFFF*(file_count-8);
  1644.       else
  1645.         position=0;
  1646.  
  1647.       /* List the files: (Starting with position) */
  1648.       display_list(position);
  1649.     }
  1650.  
  1651.  
  1652.     if(more_files)
  1653.     {
  1654.       /* Are there more files/dirtectories left to be collected? */    
  1655.       if(ExNext(lock, file_info))
  1656.       {
  1657.         /* List the file/directory if it is: */
  1658.         /* 1. A file which has the right extension. */
  1659.         /* 2. A directory. */
  1660.         if(stricmp(extension_name, (file_info->fib_FileName+
  1661.            strlen(file_info->fib_FileName)-strlen(extension_name)))==0 ||
  1662.            directory(file_info) )
  1663.         {
  1664.           /* Is this the first file/directory? */
  1665.           if(first_file)
  1666.           {
  1667.             /* first_pointer will point at the first file in our list: */
  1668.             first_pointer=(struct file_info *) save_file_info(file_info);
  1669.             
  1670.             if(first_pointer != NULL)
  1671.             {
  1672.               /* There are no more elements (for the moment) in our list: */ 
  1673.               first_pointer->next=NULL; 
  1674.               first_file=FALSE;
  1675.             }
  1676.             file_count=1;
  1677.             position=1;
  1678.           }
  1679.           else
  1680.           {
  1681.             /* save_file_info will return a pointer to the allocated */
  1682.             /* structure: */
  1683.             pointer=(struct file_info *) save_file_info(file_info);
  1684.             
  1685.             /* If we have been able to allocate space for the file we */
  1686.             /* put it into our list: */
  1687.             if(pointer !=NULL)
  1688.             {
  1689.               /* Put the new structure into the list: */
  1690.               put_in(first_pointer, pointer);       
  1691.               file_count++;
  1692.             }
  1693.           }
  1694.         
  1695.           /* If tehre are more than eight files/directories we modify */
  1696.           /* the proportional gadget: */
  1697.           if(file_count > 8)
  1698.           {
  1699.             ModifyProp
  1700.             (
  1701.               &gadget_proportional,       /* PropGadget */
  1702.               file_window,                /* Pointer */
  1703.               NULL,                       /* Requester */
  1704.               prop_info.Flags,            /* Flags */
  1705.               0,                          /* HorizPot */
  1706.               prop_info.VertPot,          /* VertPot */
  1707.               0,                          /* HorizBody */
  1708.               (ULONG) 0xFFFF*8/file_count /* VerBody */
  1709.             );            
  1710.             position=(int) prop_info.VertPot/(float) 0xFFFF*(file_count-8);
  1711.           }
  1712.           else
  1713.            position=0;
  1714.  
  1715.  
  1716.           /* List all the files: */
  1717.           display_list(position);
  1718.         }
  1719.       }
  1720.       else
  1721.       {
  1722.         /* ExNext() failed: */
  1723.         
  1724.         more_files=FALSE; /* Do not try to list any more files. */
  1725.  
  1726.         /* Check what went wrong: */
  1727.         /* If the error message is NOT "ERROR_NO_MORE_ENTRIES" something */
  1728.         /* went terrible wrong while reading: */
  1729.         if(IoErr() != ERROR_NO_MORE_ENTRIES)
  1730.         {
  1731.           request_ok("ERROR reading file/directory!");
  1732.         }
  1733.       }
  1734.     }
  1735.   } while(working);
  1736.  
  1737.   /* Clean up and leave: */
  1738.  
  1739.  
  1740.   /* This will clear the IDCMP port: */
  1741.   while( (my_gadget_message = (struct IntuiMessage *)
  1742.            GetMsg(file_window->UserPort)) )
  1743.   {
  1744.     ReplyMsg((struct Message *)my_gadget_message);
  1745.   }
  1746.  
  1747.  
  1748.   /* Deallocate the memory we have dynamically allocated: */ 
  1749.   deallocate_file_info();
  1750.  
  1751.  
  1752.   /* If we have "locked" a file/directory, "unlock" it: */
  1753.   if(file_lock)
  1754.   {
  1755.     UnLock(lock);
  1756.     file_lock=FALSE;
  1757.   }
  1758.   
  1759.   
  1760.   /* Deallocate FileInfoBlock: */
  1761.   if(file_info) FreeMem(file_info, sizeof(struct FileInfoBlock));
  1762.  
  1763.  
  1764.   /* If we have successfully opened the file_window, we close it: */
  1765.   if(file_window)
  1766.     CloseWindow(file_window);
  1767.   
  1768.   /* Leave with a message: */
  1769.   return(operation);
  1770. }
  1771.  
  1772.  
  1773.  
  1774. /* Deallocate the memory we have dynamically allocated: */ 
  1775. void deallocate_file_info()
  1776. {
  1777.   struct file_info *pointer, *temp_pointer;
  1778.  
  1779.   /* Does the first pointer point to an allocated structure? */   
  1780.   if(first_pointer)
  1781.   {
  1782.     /* Save the address of the next structure: */
  1783.     pointer=first_pointer->next;
  1784.     
  1785.     /* Deallocate the first structure: */
  1786.     FreeMem( first_pointer, sizeof(struct file_info));
  1787.  
  1788.     /* As long as pointer points to an allocated structure: */
  1789.     while(pointer)
  1790.     {
  1791.       /* Save the address of the next structure: */    
  1792.       temp_pointer=pointer->next;
  1793.       
  1794.       FreeMem( pointer, sizeof(struct file_info));
  1795.       pointer=temp_pointer;
  1796.     }
  1797.   }
  1798.   
  1799.   /* Clear first_pointer: */
  1800.   first_pointer=NULL;
  1801.  
  1802.   /* Next time we try to list the files, we start with the first_file: */
  1803.   first_file=TRUE;
  1804. }
  1805.  
  1806.  
  1807.  
  1808. /* Allocate memory for the new file/directory, and fills the structure */
  1809. /* with information. (name of the object, and if it is a directory.)   */
  1810. /* Returns a memory pointer to the allocated structure, or NULL.       */
  1811. APTR save_file_info(info)
  1812. struct FileInfoBlock *info;
  1813. {
  1814.   struct file_info *pointer;
  1815.  
  1816.   if((pointer=(struct file_info *)
  1817.     AllocMem(sizeof(struct file_info), MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  1818.   {
  1819.     /* We could NOT allocate memory for the structure! */
  1820.     request_ok("NOT enough memory!"); /* Inform the user. */
  1821.     more_files=FALSE; /* Do not list any more files/directories. */
  1822.     return(NULL);
  1823.   }
  1824.   else
  1825.   {
  1826.     /* If the file/directory name is not too long, we copy it into the */
  1827.     /* new stucture: */
  1828.     if(strlen(info->fib_FileName) < 28)
  1829.       strcpy(pointer->name, info->fib_FileName);
  1830.     else
  1831.     {
  1832.       /* The file/directory name is too long! */
  1833.       /* Inform the user: */
  1834.       
  1835.       if( directory(info))
  1836.         request_ok("Directory name too long!"); /* It is a directory. */
  1837.       else    
  1838.         request_ok("File name too long!"); /* It is a file. */
  1839.  
  1840.       /* Deallocate the structure: */
  1841.       FreeMem( pointer, sizeof(struct file_info));
  1842.       return(NULL);
  1843.     }
  1844.  
  1845.     /* Is it a file or a directory? */
  1846.     if( directory(info))
  1847.       pointer->directory=TRUE; /* It is a directory. */
  1848.     else    
  1849.       pointer->directory=FALSE; /* It is a file. */
  1850.   }
  1851.   
  1852.   /* Return the address of the allocated structure: */
  1853.   return( (APTR) pointer);
  1854. }
  1855.  
  1856.  
  1857.  
  1858. /* Will check a FileInfoBlock if it is a file or a directory. */
  1859. /* Return TRUE if it is a directory, FALSE if it is a file.   */
  1860. BOOL directory(info)
  1861. struct FileInfoBlock *info;
  1862. {
  1863.   if(info->fib_DirEntryType < 0)
  1864.     return(FALSE);
  1865.   else
  1866.     return(TRUE);
  1867. }
  1868.  
  1869.  
  1870.  
  1871. /* Put the new structure into the dynamically allocated list at the */
  1872. /* right place (sorted alphabetically, directories first):          */
  1873. void put_in(a_pointer, pointer)
  1874. struct file_info *a_pointer, *pointer;
  1875. {
  1876.   struct file_info *old_pointer=NULL;
  1877.  
  1878.   /* Move slowly down the list and try to fit in the structure: */
  1879.   while( a_pointer && file_comp(a_pointer->name, pointer->name) )
  1880.   {
  1881.     old_pointer=a_pointer;
  1882.     a_pointer=a_pointer->next;
  1883.   }
  1884.  
  1885.   if(a_pointer)
  1886.   {
  1887.     if(old_pointer)
  1888.     {
  1889.       /* Put the structure into the list: */
  1890.       pointer->next=old_pointer->next;
  1891.       old_pointer->next=pointer;
  1892.     }
  1893.     else
  1894.     {
  1895.       /* First in the list! */
  1896.       pointer->next=first_pointer;
  1897.       first_pointer=pointer;
  1898.     }
  1899.   }
  1900.   else
  1901.   {
  1902.     /* Last int the list: */
  1903.     old_pointer->next=pointer;
  1904.     pointer->next=NULL;
  1905.   }
  1906. }
  1907.  
  1908.  
  1909.  
  1910. /* This function will return TRUE if the first pointer (a_pointer) */
  1911. /* points to a file structure which should come before the second  */
  1912. /* pointers file structure.                                        */
  1913. /* ORDER: */
  1914. /* 1. DIRECTORIES sorted alphabetically. */
  1915. /* 2. FILES       sorted alphabetically. */
  1916.  
  1917. BOOL file_comp(a_pointer, pointer)
  1918. struct file_info *a_pointer, *pointer;
  1919. {
  1920.   if(a_pointer->directory == FALSE && pointer->directory)
  1921.     return(FALSE);
  1922.     
  1923.   if(a_pointer->directory == pointer->directory)
  1924.   {
  1925.     if(stricmp(a_pointer->name, pointer->name) <= 0 )
  1926.       return(TRUE);
  1927.     else
  1928.       return(FALSE);
  1929.   } 
  1930.   return(TRUE);
  1931. }
  1932.  
  1933.  
  1934.  
  1935. /* Give this function a string and a character, and it will return a */
  1936. /* pointer to the right most occurance character in you string which */
  1937. /* match your character.                                             */
  1938. STRPTR right_pos(string, sign)
  1939. STRPTR string;
  1940. char sign;
  1941. {
  1942.   STRPTR start_pos;
  1943.   
  1944.   start_pos=string;
  1945.   
  1946.   /* Go to the end: */
  1947.   while(*string != '\0')
  1948.     string++;
  1949.  
  1950.   /* Start to go backwards and check teh string: */
  1951.   while(*string != sign && string > start_pos)
  1952.     string--;
  1953.     
  1954.   if(*string==sign)
  1955.     return(string); /* We have found a matching character. */
  1956.  
  1957.   return(NULL); /* We could not find a matching character. */
  1958. }
  1959.  
  1960.  
  1961.  
  1962. /* This function will change to a new device, for example df0:. */
  1963. /* Does not return anything.                                    */
  1964. void change_device(device)
  1965. STRPTR device;
  1966. {
  1967.   strcpy(drawer_name, device); /* Change the drawer string. */
  1968.  
  1969.   adjust_string_gadgets(); /* Adjust the string gadgets. */
  1970.  
  1971.   new_drawer(); /* Start to show us the new files/directories */
  1972. }
  1973.  
  1974.  
  1975.  
  1976. /* When the user or the program has changet the drawer string, this      */
  1977. /* function is called, and will do what is necessary to start to collect */
  1978. /* the new files/directories from the disk.                              */
  1979. /* Returns TRUE if everything is OK, and FALSE if something went wrong.  */
  1980. BOOL new_drawer()
  1981. {
  1982.   STRPTR string_pointer;
  1983.  
  1984.   /* Unlock: */
  1985.   if(file_lock)
  1986.   {
  1987.     UnLock(lock);
  1988.     file_lock=FALSE;
  1989.   }
  1990.  
  1991.   /* Deallocate the memory we have dynamically allocated: */ 
  1992.   deallocate_file_info();
  1993.  
  1994.   /* Change the proportianal gadget: */
  1995.   ModifyProp
  1996.   (
  1997.     &gadget_proportional, /* PropGadget */
  1998.     file_window,          /* Pointer */
  1999.     NULL,                 /* Requester */
  2000.     prop_info.Flags,      /* Flags */
  2001.     0,                    /* HorizPot */
  2002.     0,                    /* VertPot */
  2003.     0,                    /* HorizBody */
  2004.     (ULONG) 0xFFFF        /* VerBody */
  2005.   );
  2006.  
  2007.   /* Clear the display: */
  2008.   display_list(0);
  2009.  
  2010.   more_files=FALSE;
  2011.  
  2012.   /* Try to "lock" the file/directory: */
  2013.   if((lock=Lock(drawer_name, ACCESS_READ))==NULL)
  2014.   {
  2015.     /* We could NOT lock the file/directory/device! */
  2016.     /* Inform the user: */
  2017.     string_pointer=drawer_name+strlen(drawer_name)-1;
  2018.     if(*string_pointer==':')
  2019.       request_ok("Device NOT found!");
  2020.     else
  2021.       request_ok("Device/Directory NOT found!");
  2022.  
  2023.     return(FALSE); /* ERROR */
  2024.   }
  2025.   else
  2026.   {
  2027.     /* We "locked" the file/directory! */
  2028.     file_lock=TRUE;
  2029.   }
  2030.  
  2031.   /* Now try to get some information from the file/directory: */
  2032.   if((Examine(lock, file_info))==NULL)
  2033.   {
  2034.     /* We could NOT examine the file/directory! */
  2035.  
  2036.     request_ok("ERROR reading file/directory!"); /* Inform the user. */
  2037.  
  2038.     return(FALSE); /* ERROR */
  2039.   }
  2040.  
  2041.   /* Is it a directory or a file? */
  2042.   if(directory(file_info))
  2043.   {
  2044.     /* It is a directory! */
  2045.  
  2046.     /* Since it is a directory, we will look for more files: */
  2047.     more_files=TRUE;
  2048.   }
  2049.   else
  2050.   {
  2051.     /* It is a file! */
  2052.     request_ok("NOT a valid directory name!"); /* Inform the user. */
  2053.     return(FALSE);
  2054.   }  
  2055.   return(TRUE);
  2056. }
  2057.  
  2058.  
  2059.  
  2060. /* The function parent() will try to go backwards one step in the */
  2061. /* directory path.                                                */
  2062. /* Does not return anything.                                      */
  2063. void parent()
  2064. {
  2065.   STRPTR string_pointer;
  2066.  
  2067.   /* Separate the last directory from the path: */
  2068.   if(string_pointer=right_pos(drawer_name, '/'))
  2069.   {
  2070.     /* Take away the last directory: */
  2071.     *string_pointer='\0';
  2072.   }
  2073.   else
  2074.   {
  2075.     if(string_pointer=right_pos(drawer_name, ':'))
  2076.     {
  2077.       /* Take away the last directory: */
  2078.       /* Only the device ("df0:" for example) left: */
  2079.       *(string_pointer+1)='\0';
  2080.     }
  2081.     else
  2082.     {
  2083.       /* Strange drawer_name, clear it: */
  2084.       *drawer_name='\0';
  2085.     }
  2086.   }
  2087.  
  2088.   /* Since we have messed around with the string gadgets, adjust them: */
  2089.   adjust_string_gadgets();
  2090.   
  2091.   /* Start to show the user the files etc in the new directory: */
  2092.   new_drawer();
  2093. }
  2094.  
  2095.  
  2096.  
  2097. /* You give this function a pointer to an error string, and it will open */
  2098. /* a simple requester displaying the message. The requester will go away */
  2099. /* first when the user has selected the button "OK".                     */
  2100. /* Does not return anything.                                             */
  2101. void request_ok(message)
  2102. STRPTR message;
  2103. {
  2104.   text_request.IText=message;
  2105.   
  2106.   AutoRequest
  2107.   (
  2108.     file_window,   /* Window */
  2109.     &text_request, /* BodyText */
  2110.     NULL,          /* PositiveText nothing */
  2111.     &ok_request,   /* NegativeText OK */
  2112.     NULL,          /* PositiveFlags */
  2113.     NULL,          /* NegativeFlags */
  2114.     320,           /* Width */
  2115.     72             /* Height */
  2116.   );
  2117. }
  2118.  
  2119.  
  2120.  
  2121. /* This function will also open a simple requester, but will instead      */
  2122. /* ask the user to make a choice between option1 or option2               */
  2123. /* If the user selects option1 the function returns TRUE, else it returns */
  2124. /* FALSE.                                                                 */
  2125. BOOL request_ask(message, option1, option2)
  2126. STRPTR message, option1, option2;
  2127. {
  2128.   text_request.IText=message;
  2129.   option1_request.IText=option1;
  2130.   option2_request.IText=option2;
  2131.   
  2132.   
  2133.   return( (BOOL) AutoRequest
  2134.   (
  2135.     file_window,       /* Window */
  2136.     &text_request,     /* BodyText */
  2137.     &option1_request,  /* PositiveText, TRUE */
  2138.     &option2_request,  /* NegativeText, FALSE */
  2139.     NULL,              /* PositiveFlags */
  2140.     NULL,              /* NegativeFlags */
  2141.     320,               /* Width */
  2142.     72                 /* Height */
  2143.   ));
  2144. }
  2145.  
  2146.  
  2147.  
  2148. /* This function will display the files etc which are inside the */
  2149. /* directory, starting with the file number start_pos.           */
  2150. /* Does not return anything.                                     */
  2151. void display_list(start_pos)
  2152. int start_pos;
  2153. {
  2154.   struct file_info *pointer;
  2155.   int pos, temp1;
  2156.                   /* 123456789012345678901234567890123 */
  2157.   char empty_name[]="                                 ";
  2158.   STRPTR string_pointer;
  2159.   BOOL clear;
  2160.   
  2161.   pos=0;
  2162.   
  2163.   /* Does it exist any files at all? */
  2164.   if(first_pointer)
  2165.   {
  2166.     pointer=first_pointer;
  2167.  
  2168.     /* Go through the list until you have found the file/directory */
  2169.     /* which should be shown first:                                */
  2170.     while(pointer && pos < start_pos)
  2171.     {
  2172.       pos++;
  2173.       pointer=pointer->next;
  2174.     }
  2175.     
  2176.     /* Try to show the eight files: */
  2177.     pos=0;
  2178.     while(pointer && pos < 8)
  2179.     {
  2180.       strcpy(display_text[pos], pointer->name);
  2181.       
  2182.       clear=FALSE;
  2183.       temp1=0;
  2184.       string_pointer=display_text[pos];
  2185.  
  2186.       if(pointer->directory)
  2187.       {
  2188.         /* It is a directory: */
  2189.         text_list[pos].FrontPen=3; /* Highlight it. */
  2190.  
  2191.         /* Clear everything after the name, and add the string "(Dir)". */
  2192.         while(temp1 < 28)
  2193.         {
  2194.           if(*string_pointer=='\0')
  2195.             clear=TRUE;
  2196.           if(clear)
  2197.             *string_pointer=' ';
  2198.           string_pointer++;
  2199.           temp1++;
  2200.         }
  2201.         *string_pointer='\0';
  2202.         strcat(display_text[pos], "(Dir)");
  2203.       }
  2204.       else
  2205.       {
  2206.         /* It is a file: */
  2207.         text_list[pos].FrontPen=1; /* Normal colour. */
  2208.  
  2209.         /* Clear everything after the name: */
  2210.         while(temp1 < 33)
  2211.         {
  2212.           if(*string_pointer=='\0')
  2213.             clear=TRUE;
  2214.           if(clear)
  2215.             *string_pointer=' ';
  2216.           string_pointer++;
  2217.           temp1++;
  2218.         }
  2219.         *string_pointer='\0';
  2220.       }      
  2221.       pos++;
  2222.       pointer=pointer->next; /* Next. */
  2223.     }
  2224.   }
  2225.  
  2226.   /* If there are less than eight files, show clear the rest of the */
  2227.   /* display: */
  2228.   while(pos < 8)
  2229.   {
  2230.     strcpy(display_text[pos], empty_name);
  2231.     pos++;
  2232.   }
  2233.   
  2234.   /* Show the user the new display: */
  2235.   PrintIText(file_window->RPort, text_list, 13+3, 53+1);
  2236. }
  2237.  
  2238.  
  2239.  
  2240. /* The user has selected a file or a directory. If it is a file put it */
  2241. /* into the file string, otherwise put it into the drawer string.      */
  2242. /* Returns TRUE if everything went OK, FALSE if there was a problem.   */
  2243. BOOL pick_file(file_pos)
  2244. int file_pos;
  2245. {
  2246.   struct file_info *pointer=NULL;
  2247.   STRPTR string_pointer;
  2248.   int pos=0;
  2249.   
  2250.   /* Go through the allocated list untill we find the file/directory: */
  2251.   if(first_pointer)
  2252.   {
  2253.     pointer=first_pointer;
  2254.     
  2255.     while(pointer && pos < file_pos)
  2256.     {
  2257.       pos++;
  2258.       pointer=pointer->next;
  2259.     }
  2260.   }
  2261.  
  2262.   /* Have we found the file/directory? */
  2263.   if(pointer)
  2264.   {
  2265.     if(pointer->directory)
  2266.     {
  2267.       /* It is a directory! */
  2268.       
  2269.       /* Is the drawer_name string long enough? */
  2270.       /* (+2: 1 for the NULL ('\0') character, 1 for the '\' character) */
  2271.       if((strlen(pointer->name)+strlen(drawer_name)+2) <= DRAWER_LENGTH)
  2272.       {
  2273.         /* YES!, there is enough room for it. */
  2274.         string_pointer=drawer_name+strlen(drawer_name)-1;
  2275.         if(*string_pointer==':'  || *string_pointer=='\0' )
  2276.           strcat(drawer_name, pointer->name);
  2277.         else
  2278.         {
  2279.           /* We need to add a '/' before we can add the directory. */
  2280.           strcat(drawer_name, "/");
  2281.           strcat(drawer_name, pointer->name);
  2282.         }
  2283.         
  2284.         /* Adjust the string gadgets: */
  2285.         adjust_string_gadgets();
  2286.       }
  2287.       else
  2288.       {
  2289.         /* The drawer_name is NOT big enough! */
  2290.         request_ok("Too long drawer string"); /* Inform the user. */
  2291.         return(FALSE); /* ERROR */
  2292.       }
  2293.       new_drawer();
  2294.       return(TRUE); /* OK */
  2295.     }
  2296.     else
  2297.     {
  2298.       /* It is a File! */
  2299.       /* Is the file_name string long enough? */
  2300.       /* (+1 for the NULL ('\0') character.) */
  2301.       if((strlen(pointer->name)+1) <= FILE_LENGTH)
  2302.       {
  2303.         strcpy(file_name, pointer->name);
  2304.         adjust_string_gadgets();
  2305.       }
  2306.       else
  2307.       {
  2308.         /* The file_name is NOT big enough! */
  2309.         request_ok("File name too long!"); /* Inform the user. */
  2310.         return(FALSE); /* ERROR */
  2311.       }
  2312.       return(TRUE); /* OK */
  2313.     }
  2314.   }
  2315. }
  2316.  
  2317.  
  2318.  
  2319. /* Adjust the string gadgets, so the user can */
  2320. /* at least see the last 28/22 characters.    */
  2321. /* Does not return anything.                  */
  2322. void adjust_string_gadgets()
  2323. {
  2324.   int length;
  2325.  
  2326.   length=strlen(file_name);        
  2327.  
  2328.   if(length > 28)
  2329.     string_file.DispPos=length-28;
  2330.   else
  2331.     string_file.DispPos=0;
  2332.  
  2333.   string_file.BufferPos=string_file.DispPos;
  2334.   
  2335.  
  2336.   length=strlen(drawer_name);        
  2337.  
  2338.   if(length > 22)
  2339.     string_drawer.DispPos=length-22;
  2340.   else
  2341.     string_drawer.DispPos=0;
  2342.  
  2343.   string_drawer.BufferPos=string_drawer.DispPos;
  2344.  
  2345.   /* Display the changes. */
  2346.   RefreshGadgets(&gadget_file, file_window, NULL);
  2347. }
  2348.  
  2349.  
  2350.  
  2351. /* Returns TRUE if there exist a file name, otherwise FALSE. */
  2352. BOOL last_check(name)
  2353. STRPTR name;
  2354. {
  2355.   if(*file_name == '\0')
  2356.   {
  2357.     /* No file name! */
  2358.     request_ok("NO filename selected!"); /* Inform the user. */
  2359.     return(FALSE);
  2360.   }
  2361.   else
  2362.   {
  2363.     /* Change the total_file_name. Drawer + File. */
  2364.     connect_dir_file(name);
  2365.   }
  2366.   return(TRUE);
  2367. }
  2368.  
  2369.  
  2370.  
  2371. /* This function will connect the drawer string with the file string. */
  2372. /* Does not return anything.                                          */
  2373. void connect_dir_file(name)
  2374. STRPTR name;
  2375. {
  2376.   STRPTR string_pointer;
  2377.   
  2378.        
  2379.   strcpy(name, drawer_name); /* Copy the drawer string into name. */
  2380.  
  2381.   /* Does it exist a file name? */
  2382.   if(*file_name != '\0')
  2383.   {
  2384.     /* Yes! */
  2385.     string_pointer=drawer_name+strlen(drawer_name)-1;
  2386.     if(*string_pointer==':'  || *string_pointer=='\0' )
  2387.     {
  2388.       strcat(name, file_name); /* Add the file name. */
  2389.     }
  2390.     else
  2391.     {
  2392.       strcat(name, "/"); /* Add a '\'. */
  2393.       strcat(name, file_name); /* Add the file name. */
  2394.     }
  2395.   }
  2396. }
  2397.  
  2398.  
  2399.  
  2400. /* Does not return anything. */
  2401. void delete_file_dir(total_file_name)
  2402. STRPTR total_file_name;
  2403. {
  2404.   BOOL delete_it;
  2405.  
  2406.   /* Presume the user do not want to deleta the file/dir: */
  2407.   delete_it=FALSE;
  2408.   
  2409.   if(*file_name == '\0' && *drawer_name != '\0')
  2410.   {
  2411.     /* There is no filename string, but there is something */
  2412.     /* in the drawer string. The user wants to delete a */
  2413.     /* directory: */
  2414.                  
  2415.     /* Is it a device or a directory? */
  2416.     if( *(drawer_name+strlen(drawer_name)-1) ==':')
  2417.     {
  2418.       /* The user wants to delete a device: */
  2419.       /* Not a very good idea! */
  2420.       request_ok("You can NOT delete a device!");
  2421.     }
  2422.     else
  2423.     {
  2424.       /* The user wants to delete a directory: */
  2425.                    
  2426.       /* However, it is important to check that the user */
  2427.       /* realy wants to delete it:                       */
  2428.       delete_it=request_ask("OK to delete directory?","DELETE","CANCEL");
  2429.                    
  2430.       if(delete_it)
  2431.       {
  2432.         /* YES! The user wanted to delete the directory.  */
  2433.         /* Before we try to delete it we must "unlock" it */
  2434.         if(file_lock)
  2435.         {
  2436.           UnLock(lock);
  2437.           file_lock=FALSE;
  2438.         }
  2439.       }
  2440.     }
  2441.   }
  2442.   else
  2443.   {
  2444.     if(*file_name != '\0')
  2445.     {
  2446.       /* There is something in the file_name string. The user */
  2447.       /* wants to delete a file: */
  2448.       
  2449.       /* We will here again give the user a last chance to */
  2450.       /* make up his/her mind: */
  2451.       delete_it=request_ask("OK to delete file?","DELETE","CANCEL");
  2452.     }
  2453.     else
  2454.     {
  2455.       /* Nothing in the drawer string, nor in the file string. */
  2456.       /* The user wants to delete something, but has NOT       */
  2457.       /* declared which file/directory he/she wants to delete: */
  2458.       request_ok("NO file/directory selected!");
  2459.     }
  2460.   }
  2461.   
  2462.   /* Should we delete the file/directory? */
  2463.   if(delete_it)
  2464.   {
  2465.     /* Yes! */
  2466.     
  2467.     /* Put the drawer name together with the file name: */
  2468.     connect_dir_file(total_file_name);
  2469.     
  2470.     /* We try to delete the file/directory: */
  2471.     if(DeleteFile(total_file_name))
  2472.     {
  2473.       /* We have deleted the file/directory successfully: */
  2474.               if(*file_name != '\0')
  2475.       {
  2476.         /* A file was deleted: */
  2477.         *file_name='\0'; /* Take away the file name. */
  2478.         adjust_string_gadgets(); /* Adjust the string gadgets. */
  2479.         new_drawer(); /* Show the user the remaining files. */
  2480.       }
  2481.       else
  2482.       {
  2483.         /* A directory was deleted: */
  2484.         parent(); /* Go back one directory. */  
  2485.       }
  2486.     }
  2487.     else
  2488.     {
  2489.       /* Something went wrong: */
  2490.       if(*file_name != '\0')
  2491.         request_ok("Could NOT delete the file!");
  2492.       else
  2493.         request_ok("Could NOT delete directory!");
  2494.       
  2495.       /* Since we have unlocked the directory/file we have */
  2496.       /* to lock it again, and clean up the display: */
  2497.       new_drawer();
  2498.     }
  2499.   }
  2500. }
  2501.  
  2502. /* THE END */
  2503.  
  2504.